$(document).ready(function(){
	
	$.getJSON(getRootPath()+ "/MainMenu/profit/totalSelledAmount.htm",{type:$("#countDate").val()},function(data){
		$("#yesterSelledAmount").val(data.sum);
	});
	
	$("#countDate").change(function(){
		$.getJSON(getRootPath()+ "/MainMenu/profit/totalSelledAmount.htm",{type:$("#countDate").val()},function(data){
			$("#yesterSelledAmount").val(data.sum);
		});
	});
	
	$("#generateBtn").click(function(){
		if($("#yesterSelledAmount").val()==""){
			alert("昨日销售额不能为空");
			return;
		}
		if($("#profitReturnPercent").val()==""){
			alert("返利比例不能为空");
			return;
		}
		$("#profitTable").load(getRootPath()+ "/MainMenu/profit/generateProfitTable.htm",$("#profitForm").serializeArray());
	});
	
	$("#calcBtn").click(function(){
		var amount = $("#yesterSelledAmount").val();
		var percent = $("#profitReturnPercent").val();
		var count = $("#shouldReturnProfitMemberCount").val();
		var totalReturnProfit=accMul(amount,accDiv(percent,100));
		$("#avgReturnProfitAmount").val(forDight(accDiv(totalReturnProfit,count),2));
		$("#totalProfitAmount").val(forDight(totalReturnProfit,2));
	});
});